package emulator.unittest.hardware.nmos6502.commands;

import static org.junit.Assert.assertEquals;

import org.junit.Test;

import emulator.EmulatorException;
import emulator.hardware.HwByte;
import emulator.hardware.nmos6502.Cpu6502;
import emulator.hardware.nmos6502.Flags6502;
import emulator.hardware.nmos6502.commands.INC;
import emulator.unittest.hardware.nmos6502.MockOperand;

public class INCTest {

	@Test
	public void testIncPositive() throws EmulatorException {
		executeAndCheckINC(0x3F, 0);
	}

	@Test
	public void testIncNegative() throws EmulatorException {
		executeAndCheckINC(0x7F, Flags6502.FLAG_NEGATIVE);
	}

	@Test
	public void testIncZero() throws EmulatorException {
		executeAndCheckINC(0xFF, Flags6502.FLAG_ZERO);
	}

	private void executeAndCheckINC(int val, int expected_flags)
			throws EmulatorException {
		Cpu6502 cpu = new Cpu6502();
		MockOperand operand = new MockOperand(val);
		new INC().execute(cpu, operand);
		assertEquals(new HwByte(val+1), operand.getByte());
		assertEquals(new Flags6502(expected_flags), cpu.getFlags());
	}

}
